

%% load panel data
load('../../baseline_model/data_panel.mat')
load('../../baseline_model/data.mat')
countries_full=unique(data.cown);


%% aggregate data for Cold War period, 1950-1989

countries=unique(data_panel.cown);

data=data_panel(1:length(countries),[1:3,6:end]);
for n=1:length(countries)
    dn=data_panel(data_panel.cown==countries(n)&data_panel.year<=1989,:);
    data(n,1:3)=dn(1,1:3);
    data(n,4:end)=array2table(nanmean(table2array(dn(:,6:end))));
end

outcomes=outcomes_panel(1:length(countries),[1:3,5:end]);
for n=1:length(countries)
    dn=outcomes_panel(outcomes_panel.cown==countries(n)&outcomes_panel.year<=1989,:);
    outcomes(n,1:3)=dn(1,1:3);
    outcomes(n,4:end)=array2table(1*(sum(table2array(dn(:,5:end)))>0));
end

missing=find(~isfinite(data.gdp_pc)|~isfinite(data.pop)...
    |~isfinite(data.polity)|~isfinite(data.USally));
data(missing,:)=[];
outcomes(missing,:)=[];


%%
nmissing=arrayfun(@(n)sum(n==data.cown)>0,countries_full);
clearvars -except data outcomes nmissing
save('data_cw.mat')

